#ifndef DIRECTORY_CACHE_H
#define DIRECTORY_CACHE_H
class ItemInfo;
class DirectoryWatcher;
class DirectoryCacheEntry
{
public:
    wxString path;
    bool changed;
    wxMutex *accessGuard;
    vector<ItemInfo *> content;
    unsigned int useCount;
};
class DirectoryCache : public wxThread
{
public:
    DirectoryCache();
    void Initialize();
    virtual ExitCode Entry();
    void Signal(unsigned int handleId);
    DirectoryCacheEntry *WatchDirectory(const wxString &path);
	void UnwatchDirectory(const wxString &path);
    void End();
    bool GetDirectoryContent(const wxString &path, vector<ItemInfo *> &content, bool forceRefresh = false);
    void RegisterWatcher(DirectoryWatcher *watcher);
    void CleanHandles();
	void CleanHandles2();
    void MarkUnused(const wxString &path);
	void StartWrite();
	void EndWrite();
	void StartRead();
	void EndRead();
	void DowngradeToReader();
	void UpgradeToWriter();
	void EndAccess();
private:
    HANDLE *handles;
    unsigned int handlesCount;
    map<wxString, DirectoryCacheEntry*> cacheEntriesByPath;
    map<unsigned int, DirectoryCacheEntry*> cacheEntriesByIndex;
    bool done;
	bool *handlesToRemove;
    vector<DirectoryWatcher*> watchers;
    DWORD lastClean;
	wxCondition *threadCondition;
	wxMutex *conditionMutex;
	RWLOCK readWriteLock;
};
#endif